# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
        if p.val > q.val:
            p, q = q, p
        node = root
        while True:
            if node.val == q.val or node.val == p.val:
                return node
            if p.val < node.val < q.val:
                return node
            if p.val < node.val:
                node = node.left
            else:
                node = node.right


if __name__ == '__main__':
    so = Solution()
    s = [1, 0, 3, 4, 0, 1]
    r = so.isPalindrome(s)
    print(r)
